﻿@model List<DataAccess.Models.Promoter>
@{
    ViewBag.Title = "Index";
}
 
  
 
<div class="container body-content">
    <h2>推广者列表</h2>
    <p>
        <button type="button" class="btn btn-primary" id="add">新增</button>
    </p>
</div>
    <table class="table">
        <tr>
            <th>
                Id
            </th>
            <th>用户名</th>
            <th>服务开始时间</th>
            <th>服务结束时间</th>
            <th>产品库数量</th>
            <th>是否启用</th>
            <th>操作</th>

        </tr>

        @foreach (var item in Model)
        {
            <tr>
                <td>@item.Id</td>
                <td>@item.Username</td>
                <td>@item.StartTime</td>
                <td>@item.EndTime</td>
                <td>@item.ProductNum</td>
                <td>@item.IsEnabled</td>
                <td>
                   
                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#robotCode" data-whatever="@item.Id">加机器人邀请码 </button>


                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@item.Id">修改密码 </button>


                    @Html.ActionLink("修改","edit",new {id=item.Id})

                  


                    <a href="javascript:if(confirm('确定要删除吗？')) window.location.href='/promoter/delete?id=@item.Id' ">删除</a>




                </td>

            </tr>
        }





    </table>


<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">修改密码</h4>
            </div>
            <form method="post" action="/promoter/UpdatePW">
                <div class="modal-body">

                    <input type="hidden" id="proid" name="proid" />
                    <div class="form-group">
                        <label for="password1" class="control-label">密码</label>
                        <input type="text" class="form-control" id="password1" name="password1">
                    </div>
                    <div class="form-group">
                        <label for="password2" class="control-label">重复密码</label>
                        <input type="text" class="form-control" id="password2" name="password2">
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>


<div class="modal fade" id="robotCode" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">添加机器人邀请码</h4>
            </div>
            <form method="post" action="/promoter/addRobot">
                <div class="modal-body">

                    <input type="hidden" id="pid" name="pid" />
                    <div class="form-group">
                        <label for="robotNum" class="control-label">添加数量</label>
                        <input type="text" class="form-control" id="robotNum" name="robotNum">
                    </div>
                     

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>


    $('#add').click(function () {
        window.location.href = "/promoter/add";
    })


    $('#exampleModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var recipient = button.data('whatever');

        //var modal = $(this)
        //modal.find('.modal-body input').val(recipient)

        $('#proid').val(recipient);
    })

    $('#robotCode').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var recipient = button.data('whatever');

        //var modal = $(this)
        //modal.find('.modal-body input').val(recipient)

        $('#pid').val(recipient);
    })


</script>